/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.edu.buaa.sei.dm.dianping.building;

import cn.edu.buaa.sei.dm.dianping.preprocess.Utility;
import cn.edu.buaa.sei.dm.dianping.resolution.Location;
import java.awt.Color;
import java.awt.Graphics;
import java.util.Map;
import javax.swing.JPanel;

/**
 *
 * @author Qiang
 */
public class DensityGridFrame extends javax.swing.JFrame {

    /**
     * Creates new form DensityGridFrame
     */
    public DensityGridFrame() {
        initComponents();
        final ShopDensity density = new ShopDensity();
        density.initialize(Utility.loadLocationMap());
        
        System.out.println(density.getNotzeroCount());
        int[] rlevels = density.getRadiusCount();
        System.out.println("level1:" + rlevels[0]);
        System.out.println("level2:" + rlevels[1]);
        System.out.println("level3:" + rlevels[2]);
        System.out.println("level4:" + rlevels[3]);
        JPanel panel = new JPanel(){

            @Override
            public void paint(Graphics g) {
                super.paint(g);
                
//                for (int i = 0; i < density.getSliceCount(); i++) {
//                    for (int j = 0; j < density.getSliceCount(); j++) {
//                        int r = 0;
//                        switch (density.getRadius(i, j)) {
//                            case 4:
//                                r = 6;
//                                g.setColor(new Color(255, 200, 200));
//                                break;
//                            case 3:
//                                r = 4;
//                                g.setColor(new Color(0, 150, 150));
//                                break;
//                            case 2:
//                                r = 3;
//                                g.setColor(new Color(0, 100, 100));
//                                break;
//                            case 1:
//                                r = 1;
//                                g.setColor(new Color(255, 0, 0));
//                                break;
//                            default:
//                                r = 0;
//                                g.setColor(Color.white);
//                                break;
//                        }
//                        g.fillOval(i * 2 - r, j * 2 - r, r * 2, r * 2);
//                    }
//                }
                g.setColor(new Color(255, 200, 200));
                for (int i = 0; i < density.getSliceCount(); i++) {
                    for (int j = 0; j < density.getSliceCount(); j++) {
                        if (density.getRadius(i, j) == 4)
                            g.fillRect(i * 2 - 5, j * 2 - 5, 5 * 2, 5 * 2);
                    }
                }
//                g.setColor(new Color(255, 150, 150));
//                for (int i = 0; i < density.getSliceCount(); i++) {
//                    for (int j = 0; j < density.getSliceCount(); j++) {
//                        if (density.getRadius(i, j) == 3)
//                            g.fillOval(i * 2 - 4, j * 2 - 4, 4 * 2, 4 * 2);
//                    }
//                }
                g.setColor(new Color(255, 100, 100));
                for (int i = 0; i < density.getSliceCount(); i++) {
                    for (int j = 0; j < density.getSliceCount(); j++) {
                        if (density.getRadius(i, j) == 2)
                            g.fillRect(i * 2 - 3, j * 2 - 3, 3 * 2, 3 * 2);
                    }
                }
                g.setColor(new Color(100, 0, 0));
                for (int i = 0; i < density.getSliceCount(); i++) {
                    for (int j = 0; j < density.getSliceCount(); j++) {
                        if (density.getRadius(i, j) == 1)
                            g.fillRect(i * 2 - 1, j * 2 - 1, 1 * 2, 1 * 2);
                    }
                }
            }
            
        };
        
        this.add(panel);
        panel.setBackground(Color.white);
        panel.setBounds(0, 0, 1000, 1000);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(DensityGridFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(DensityGridFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(DensityGridFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(DensityGridFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new DensityGridFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
